/**
 * API密钥调试程序
 * 检查保存和读取的API密钥实际值
 */
public class APIKeyDebug {
    
    public static void main(String[] args) {
        System.out.println("=== API密钥调试 ===\n");
        
        UserPreferences preferences = new UserPreferences();
        
        System.out.println("当前API密钥配置:");
        System.out.println("OpenWeatherMap密钥: '" + preferences.getOpenWeatherMapApiKey() + "'");
        System.out.println("OpenWeatherMap密钥长度: " + preferences.getOpenWeatherMapApiKey().length());
        System.out.println("OpenWeatherMap密钥有效: " + preferences.hasValidOpenWeatherMapKey());
        System.out.println();
        
        System.out.println("WeatherAPI.com密钥: '" + preferences.getWeatherApiComKey() + "'");
        System.out.println("WeatherAPI.com密钥长度: " + preferences.getWeatherApiComKey().length());
        System.out.println("WeatherAPI.com密钥有效: " + preferences.hasValidWeatherApiComKey());
        System.out.println();
        
        // 测试设置一个有效的OpenWeatherMap密钥
        System.out.println("设置测试OpenWeatherMap密钥...");
        String testOpenWeatherKey = "8f7e5afc2937d5a681d09356b53f6de7"; // 32字符的有效格式
        preferences.setOpenWeatherMapApiKey(testOpenWeatherKey);
        
        System.out.println("重新读取密钥:");
        System.out.println("OpenWeatherMap密钥: '" + preferences.getOpenWeatherMapApiKey() + "'");
        System.out.println("OpenWeatherMap密钥有效: " + preferences.hasValidOpenWeatherMapKey());
        System.out.println();
        
        // 测试两个API服务
        System.out.println("测试API服务:");
        
        // 测试OpenWeatherMap
        WeatherAPIManager openWeatherService = new WeatherAPIManager(preferences);
        System.out.println("OpenWeatherMap服务可用: " + openWeatherService.isServiceAvailable());
        long openWeatherLatency = openWeatherService.testConnection();
        System.out.println("OpenWeatherMap连接测试: " + (openWeatherLatency > 0 ? openWeatherLatency + "ms" : "失败"));
        
        // 测试WeatherAPI.com
        WeatherAPIComService weatherApiService = new WeatherAPIComService(preferences);
        System.out.println("WeatherAPI.com服务可用: " + weatherApiService.isServiceAvailable());
        long weatherApiLatency = weatherApiService.testConnection();
        System.out.println("WeatherAPI.com连接测试: " + (weatherApiLatency > 0 ? weatherApiLatency + "ms" : "失败"));
        
        System.out.println("\n调试完成！");
    }
} 